package player;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;

public class CloseBtn extends JButton{

	public static void main(String[] args) {
		JFrame jFrame = new JFrame();
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jFrame.setSize(600, 400);
		jFrame.setLayout(null);
		CloseBtn closeBtn = new CloseBtn();
		closeBtn.setBounds(0, 0, closeBtn.icon.getIconWidth(), closeBtn.icon.getIconHeight());		
		jFrame.add(closeBtn);
		jFrame.setVisible(true);
	}
	
	ImageIcon icon = null; 
    
	 String iconName = "image/close.png";
	 
	    public CloseBtn(){  
	    	setCursor(new Cursor(Cursor.HAND_CURSOR));
	        setBorder(null);//取消边框  
	        icon = new ImageIcon(iconName);  
	        setBackground(null);  
	        setOpaque(false);  
	        
	        addMouseListener(new MouseAdapter() {
	        	@Override
	        	public void mouseEntered(MouseEvent e) {
	        		super.mouseEntered(e);
	        		iconName = "image/close2.png";
	        		icon = new ImageIcon(iconName);
	        		repaint();
	        	}
	        	@Override
	        	public void mouseExited(MouseEvent e) {
	        		super.mouseExited(e);
	        		iconName = "image/close.png";
	        		icon = new ImageIcon(iconName);
	        		repaint();
	        		
	        	}
	        	@Override
	        	public void mouseClicked(MouseEvent e) {
	        		super.mouseClicked(e);
	        		PlayerMain.exit();
	        	}
			});
	          
	    }  
	      
	    public void paintComponent(Graphics g){  
	    	
	        g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), this);  
	    }  
}
